*Paper: Fiscal Rules, Corruption and Electoral Accountability - Replication Files

*NB: the version of rdrobust is: "version 9.1.0  2022-10-28" 
*which rdrobust

clear all
cap log close 
set more off


**Global files
global folder "/Users/tommasogiommoni/Dropbox/Determinants of corruption/Stability pact and corruption/Replication files JOP"


********************************************************************************
****----						Dataset open 					    	----**** 
********************************************************************************

use "$folder/Data/dataset_feb2024.dta", clear

**-- Global

global controls8 proportion_female_Elected_lag av_age_Elected_lag  victory_margin_lag age_mayor_lag gender_mayor_lag
global covs_bandwidth 
global FE_regres anno id_provincia
global control_set $controls8
global cluster_regr codcom 

**-- Panel dataset

xtset codcom anno
fvset base 2012 anno

**-- Additional cleaning

keep  if population_anagrafe<10000

gen first_term=0 if term_limit==1
replace first_term=1 if term_limit==0

gen election_postReform=(year_election==2013 & anno>2013)
replace election_postReform=1 if year_election==2014 & anno>2014

gen S_ES=S*electoral_period
gen S_TL=S*term_limit
gen S_edu=S*high_education

gen T_ES=T*electoral_period
gen T_TL=T*term_limit
gen T_edu=T*high_education

gen ST_ES=ST*electoral_period
gen ST_TL=ST*term_limit
gen ST_edu=ST*high_education

gen electoral_period2=election_year
replace electoral_period2=0 if electoral_period2==. // la variabile election_year ha molti missing in anni non elettorali

gen S_ES2=S*electoral_period2
gen T_ES2=T*electoral_period2
gen ST_ES2=ST*electoral_period2

********************************************************************************
****----						Analysis 					    		----**** 
********************************************************************************

****---- Analysis optimal bandwidth ----****

  capture drop  Scorruption_PC*  Scorruption_exp_log* Bcorruption_PC*  Bcorruption_exp_log*
  capture drop band* sample* 
foreach var in corruption_PC  corruption_exp_log{
qui rdrobust `var' P if anno>2012  & population_anagrafe<10000 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs()
local band1=e(h_l)
qui rdrobust `var' P if anno<2013  & population_anagrafe<10000 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs()
local band2=e(h_l)
local band=(`band1'+`band2')/2
display "`band'"
gen	B`var'=(`band1'+`band2')/2
gen S`var' = abs(P)<B`var'

}

qui reghdfe corruption_PC_sd S P T ST PT PS PST S_ES2 T_ES2 ST_ES2 electoral_period2    $control_set term_limit_lag av_education_Elected_lag education_mayor_lag if Scorruption_PC==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg1
qui reghdfe corruption_PC_sd S P T ST PT PS PST S_TL T_TL ST_TL term_limit  $control_set av_education_Elected_lag education_mayor_lag if Scorruption_PC==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg2
qui reghdfe corruption_PC_sd S P T ST PT PS PST S_edu T_edu ST_edu high_education  $control_set term_limit_lag if Scorruption_PC==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg3

qui reghdfe corruption_exp_log_sd S P T ST PT PS PST S_ES2 T_ES2 ST_ES2 electoral_period2   $control_set term_limit_lag av_education_Elected_lag education_mayor_lag if Scorruption_exp_log==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg11
qui reghdfe corruption_exp_log_sd S P T ST PT PS PST S_TL T_TL ST_TL term_limit   $control_set av_education_Elected_lag education_mayor_lag if Scorruption_exp_log==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg21
qui reghdfe corruption_exp_log_sd S P T ST PT PS PST S_edu T_edu ST_edu high_education   $control_set term_limit_lag if Scorruption_exp_log==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg31

****---- Analysis augmented bandwidth (+50%) ----****

  capture drop  Scorruption_PC*  Scorruption_exp_log* Bcorruption_PC*  Bcorruption_exp_log*
  capture drop band* sample* 
foreach var in corruption_PC  corruption_exp_log{
qui rdrobust `var' P if anno>2012  & population_anagrafe<10000 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs()
local band1=e(h_l)
qui rdrobust `var' P if anno<2013  & population_anagrafe<10000 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs()
local band2=e(h_l)
local band=(`band1'+`band2')/1.33
display "`band'"
gen	B`var'2=(`band1'+`band2')/1.33
gen S`var'2 = abs(P)<B`var'2

}

qui reghdfe corruption_PC_sd S P T ST PT PS PST S_ES2 T_ES2 ST_ES2 electoral_period2    $control_set term_limit_lag av_education_Elected_lag education_mayor_lag if Scorruption_PC2==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg1_1
qui reghdfe corruption_PC_sd S P T ST PT PS PST S_TL T_TL ST_TL term_limit  $control_set  av_education_Elected_lag education_mayor_lag if Scorruption_PC2==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg2_1
qui reghdfe corruption_PC_sd S P T ST PT PS PST S_edu T_edu ST_edu high_education  $control_set term_limit_lag if Scorruption_PC2==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg3_1

qui reghdfe corruption_exp_log_sd S P T ST PT PS PST S_ES2 T_ES2 ST_ES2 electoral_period2   $control_set term_limit_lag av_education_Elected_lag education_mayor_lag if Scorruption_exp_log2==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg11_1
qui reghdfe corruption_exp_log_sd S P T ST PT PS PST S_TL T_TL ST_TL term_limit   $control_set av_education_Elected_lag education_mayor_lag if Scorruption_exp_log2==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg21_1
qui reghdfe corruption_exp_log_sd S P T ST PT PS PST S_edu T_edu ST_edu high_education   $control_set term_limit_lag if Scorruption_exp_log2==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg31_1

****---- Analysis augmented bandwidth (+25%) ----****

  capture drop  Scorruption_PC*  Scorruption_exp_log* Bcorruption_PC*  Bcorruption_exp_log*
  capture drop band* sample* 
foreach var in corruption_PC  corruption_exp_log{
qui rdrobust `var' P if anno>2012  & population_anagrafe<10000 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs()
local band1=e(h_l)
qui rdrobust `var' P if anno<2013  & population_anagrafe<10000 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs()
local band2=e(h_l)
local band=(`band1'+`band2')/1.6
display "`band'"
gen	B`var'3=(`band1'+`band2')/1.6
gen S`var'3 = abs(P)<B`var'3

}

qui reghdfe corruption_PC_sd S P T ST PT PS PST S_ES2 T_ES2 ST_ES2 electoral_period2    $control_set term_limit_lag av_education_Elected_lag education_mayor_lag if Scorruption_PC3==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg1_2
qui reghdfe corruption_PC_sd S P T ST PT PS PST S_TL T_TL ST_TL term_limit  $control_set  av_education_Elected_lag education_mayor_lag if Scorruption_PC3==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg2_2
qui reghdfe corruption_PC_sd S P T ST PT PS PST S_edu T_edu ST_edu high_education  $control_set term_limit_lag if Scorruption_PC3==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg3_2

qui reghdfe corruption_exp_log_sd S P T ST PT PS PST S_ES2 T_ES2 ST_ES2 electoral_period2   $control_set term_limit_lag av_education_Elected_lag education_mayor_lag if Scorruption_exp_log3==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg11_2
qui reghdfe corruption_exp_log_sd S P T ST PT PS PST S_TL T_TL ST_TL term_limit   $control_set av_education_Elected_lag education_mayor_lag if Scorruption_exp_log3==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg21_2
qui reghdfe corruption_exp_log_sd S P T ST PT PS PST S_edu T_edu ST_edu high_education   $control_set term_limit_lag if Scorruption_exp_log3==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store reg31_2

****---- Table ----****

esttab reg1 reg11 reg2 reg21 reg3 reg31 using "$folder/Tables/TableA18_panelA.tex", compress keep(ST ST_ES2 ST_TL ST_edu) se r2 staraux collabels(, none) ml(,none) cells(b(star fmt (%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) replace
esttab reg1_2 reg11_2 reg2_2 reg21_2 reg3_2 reg31_2 using "$folder/Tables/TableA18_panelB.tex", compress keep(ST ST_ES2 ST_TL ST_edu) se r2 staraux collabels(, none) ml(,none) cells(b(star fmt (%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) replace
esttab reg1_1 reg11_1 reg2_1 reg21_1 reg3_1 reg31_1 using "$folder/Tables/TableA18_panelC.tex", compress keep(ST ST_ES2 ST_TL ST_edu) se r2 staraux collabels(, none) ml(,none) cells(b(star fmt (%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) replace
